<?php

namespace App\Listeners;

use App\Events\EventCancelConsignmentNote;
use App\Jobs\CancelConsignmentNoteQueue;
use App\Services\Warehouse\OrderGoodsInventoryCarryingDetailService;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class EventListenerCancelConsignmentNote
{
    protected $OrderGoodsInventoryCarryingDetailService;
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct(OrderGoodsInventoryCarryingDetailService $orderGoodsInventoryCarryingDetailService)
    {
        $this->OrderGoodsInventoryCarryingDetailService=$orderGoodsInventoryCarryingDetailService;
    }

    /**
     * Handle the event.
     *
     * @param  EventCancelConsignmentNote  $event
     * @return void
     */
    public function handle(EventCancelConsignmentNote $event)
    {
        $order_info=$event->order_info;
        $returndata=$this->OrderGoodsInventoryCarryingDetailService->DisposeConsignmentNote($order_info['order_sn'],$order_info['k3cn_sn']);
        if($returndata){
            CancelConsignmentNoteQueue::dispatch($returndata[0])->onQueue('CancelConsignmentNoteQueue');
        }else{
            $data=[
                'order_sn'=>$order_info['order_sn'],
                'o_status'=>6
            ];
            $this->OrderGoodsInventoryCarryingDetailService->UpdateO_statusBatch($data);
        }
    }
}
